package org.zjz.basket.global;

import lombok.AllArgsConstructor;
import lombok.Data;
import org.zjz.basket.enums.ResultStatusEnum;

/**
 * Desc: 统一结果
 *
 * @author gezq
 * @since 9:44 AM - 4/27/2022
 */
@Data
@AllArgsConstructor
public class Result<T> {
    private int code;
    private String msg;
    private T data;

    public static <T> Result<T> success(T data) {
        return result(ResultStatusEnum.SUCCESS, data);
    }

    public static <T> Result<T> fail(T data) {
        return result(ResultStatusEnum.FAIL, data);
    }

    public static <T> Result<T> result(ResultStatusEnum status, T data) {
        return new Result<>(status.getCode(), status.getMsg(), data);
    }
}
